<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        *{
            margin: 0 auto;
        }
        body{
            background-color: #343a40;
        }
        #kuan{
            background-color: #323232;
            width: 500px;
            height: 500px

        }
    </style>
</head>
<body>
<div class="container" style="width: 100%; margin-top: 40px" >
    <form action="" id="kuan" >
        <div ><input type="text" name="username" placeholder="请输入用户名" @blur="check()">{{info}}</div>
        <div ><input type="text" name="nick" placeholder="请输入昵称" >             </div>
        <div ><input type="password" name="password" placeholder="请输入密码" >     </div>
        <div ><input type="password" name="rpassword" placeholder="请再次输入密码" > </div>
        <div ><input type="button" value="注册" @click="reg()">                    </div>

    </form>
</div>
<!--引入Vue和axios-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.js"></script>
<script>
    let reg_v = new Vue({
        el:"form",
        data:{
            info:"",
        },
        methods:{
            reg:function (){
                let data = new FormData(document.querySelector("form"));
                axios.post("/insert",data).then(function (){
                    location.href = "/login.html";
                })
            },
            check:function (){
                let data = new FormData(document.querySelector("form"));
                axios.post("/check",data).then(function (response){
                    if (response.data==1){
                       reg_v.info="用户可用";
                    }else {
                       reg_v.info="用户已存在!!!";
                    }
                })
            }
        }
    })
</script>
</body>
</html>